<template>
	<view class="container">
		<!-- #ifndef MP -->
		<view class="tui-status-bar"></view>
		<!-- #endif -->
		<view class="tui-page-title">登录</view>
		<view class="tui-form">
			<view class="tui-view-input">
				<tui-list-cell :hover="false" :lineLeft="false" backgroundColor="transparent">
					<view class="tui-cell-input">
						<tui-icon name="people" color="#6d7a87" :size="20"></tui-icon>

						<input :adjust-position="false" :value="mobile" placeholder="请输入手机号/账号" placeholder-class="tui-phcolor" maxlength="11" @input="inputMobile" />
						<view v-show="mobile" @tap="clearInput(1)"><tui-icon name="close-fill" :size="16" color="#bfbfbf"></tui-icon></view>
					</view>
				</tui-list-cell>
				<tui-list-cell :hover="false" :lineLeft="false" backgroundColor="transparent">
					<view class="tui-cell-input">
						<tui-icon name="pwd" color="#6d7a87" :size="20"></tui-icon>
						<input
							:adjust-position="false"
							:value="password"
							placeholder="请输入密码"
							:password="true"
							placeholder-class="tui-phcolor"
							type="text"
							maxlength="36"
							@input="inputPwd"
						/>
						<view v-show="password" @tap="clearInput(2)"><tui-icon name="close-fill" :size="16" color="#bfbfbf"></tui-icon></view>
					</view>
				</tui-list-cell>
			</view>
			<view class="tui-cell-text">
				<!-- <view class="tui-color-primary" hover-class="tui-opcity" :hover-stay-time="150" @tap="href(1)">忘记密码？</view> -->
				<view hover-class="tui-opcity" :hover-stay-time="150">
					没有账号？
					<text class="tui-color-primary" @tap="href(2)">注册</text>
				</view>
			</view>
			<view class="tui-btn-box"><tui-button @tap="toLogin" :disabledGray="true" :disabled="disabled" :shadow="true" shape="circle">登录</tui-button></view>
		</view>
		<!-- <view class="tui-login-way" v-if="!popupShow"><view hover-class="tui-opcity" :hover-stay-time="150" @tap="showOtherLogin">其他方式登录</view></view> -->
		<!-- 		<tui-bottom-popup :mask="false" backgroundColor="transparent" :show="popupShow">
			<view class="tui-auth-login"> -->
		<!-- #ifndef MP -->
		<!-- <view class="tui-icon-platform" hover-class="tui-opcity" :hover-stay-time="150"><image src="/static/images/share/icon_qq.png" class="tui-login-logo"></image></view> -->
		<!-- #endif -->
		<!-- #ifdef APP-PLUS || MP-WEIXIN || H5 -->
		<!-- 		<view class="tui-icon-platform" hover-class="tui-opcity" :hover-stay-time="150">
					<image src="/static/images/share/icon_wechat.png" class="tui-login-logo"></image>
				</view> -->
		<!-- #endif -->
		<!-- #ifndef MP -->
		<!-- 	<view class="tui-icon-platform" hover-class="tui-opcity" hover-stay-time="150">
					<image src="/static/images/share/icon_sina.png" class="tui-login-logo"></image>
				</view> -->
		<!-- #endif -->
		<!-- 	</view>
		</tui-bottom-popup> -->
	</view>
</template>

<script>
import ImStorage from '../../../sdk/utils/ImStorage.js';
import ImEnum from '../../../sdk/enums/index.js';
import ImConfig from '../../../sdk/config/index.js';
export default {
	computed: {
		disabled: function() {
			let bool = true;
			if (this.mobile && this.password) {
				bool = false;
			}
			return bool;
		}
	},
	data() {
		return {
			mobile: 'zenghj',
			password: '123',
			popupShow: false
		};
	},
	onLoad(options) {
		setTimeout(() => {
			// this.logout();
		}, 0);
	},
	methods: {
		toLogin() {
			if(ImConfig.userMock){
				this.BenderSdk.loginIm(ImConfig.userMock,new Date().getTime())
				uni.redirectTo({
					url: '/pages/chat/chat'
				});
			}else{
				if (!this.BenderSdk.loginSatet) {
					let token = '';
					this.BenderSdk.BenderHttpApi.loginApi(this.mobile, this.password).then(res=>{
						let loginState = this.BenderSdk.loginIm(ImConfig.userMock, res.data.sessionKey);
							if (loginState) {
								/**
								 * 设置登陆信息
								 */
								const user = res.data;
								let loginUser = {
									id: user.sessionKey,
									name: user.userName,
									accountName: user.uuid,
									avatar: user.avatar,
									phone: user.phone,
									sex: '男',
									remark: user.otherInfo
								};
								ImStorage.setImStorageSync(ImEnum.ImStorageEnum.loginUserInfo, loginUser);
								let loginInfo = {
									userName: this.mobile,
									pwd: this.password,
									token: res.data.sessionKey
								};
								ImStorage.setImStorageSync(ImEnum.ImStorageEnum.loginNameAndPaw, loginInfo);
								uni.redirectTo({
									url: '/pages/chat/chat'
								});
							} else {
								uni.showModal({
									title: '系统服务错误，请联系管理员',
									confirmText: '确定',
									confirmColor: 'green',
									showCancel: false,
									success: function(res) {
										if (res.confirm) {
											uni.reLaunch({
												url: '/pages/login/login/login'
											});
										}
									}
								});
							}
						
					});
				} else {
					uni.redirectTo({
						url: '/pages/chat/chat'
					});
				}
			}
			
			
		},
		inputMobile: function(e) {
			this.mobile = e.detail.value;
		},
		inputPwd: function(e) {
			this.password = e.detail.value;
		},
		clearInput(type) {
			if (type == 1) {
				this.mobile = '';
			} else {
				this.password = '';
			}
		},
		href(type) {
			let url = '/pages/login/forgetPwd/forgetPwd';
			if (type == 2) {
				url = '/pages/login/reg/reg';
			}
			uni.navigateTo({
				url: url
			});
		},
		showOtherLogin() {
			//打开后 不再关闭
			this.popupShow = true;
		}
	},
	created() {
		// let nameAndPaw = ImStorage.getImStorageSync(ImEnum.ImStorageEnum.loginNameAndPaw);
		// if (nameAndPaw) {
		// 	this.mobile = nameAndPaw.userName;
		// 	this.password = nameAndPaw.pwd;
		// 	this.toLogin();
		// }
	}
};
</script>

<style lang="scss">
.container {
	.tui-status-bar {
		width: 100%;
		height: var(--status-bar-height);
	}

	.tui-page-title {
		margin-top: 100rpx;
		width: 100%;
		font-size: 48rpx;
		font-weight: bold;
		color: $uni-text-color;
		line-height: 42rpx;
		padding: 40rpx;
		box-sizing: border-box;
	}

	.tui-form {
		padding-top: 50rpx;

		.tui-view-input {
			width: 100%;
			box-sizing: border-box;
			padding: 0 40rpx;

			.tui-cell-input {
				width: 100%;
				display: flex;
				align-items: center;
				padding-top: 48rpx;
				padding-bottom: $uni-spacing-col-base;

				input {
					flex: 1;
					padding-left: $uni-spacing-row-base;
				}

				.tui-icon-close {
					margin-left: auto;
				}
			}
		}

		.tui-cell-text {
			width: 100%;
			padding: $uni-spacing-col-lg $uni-spacing-row-lg;
			box-sizing: border-box;
			font-size: $uni-font-size-sm;
			color: $uni-text-color-grey;
			display: flex;
			align-items: center;
			justify-content: space-between;

			.tui-color-primary {
				color: $uni-color-primary;
			}
		}

		.tui-btn-box {
			width: 100%;
			padding: 0 $uni-spacing-row-lg;
			box-sizing: border-box;
			margin-top: 80rpx;
		}
	}

	.tui-login-way {
		width: 100%;
		font-size: 26rpx;
		color: $uni-color-primary;
		display: flex;
		justify-content: center;
		position: fixed;
		left: 0;
		bottom: 80rpx;

		view {
			padding: 12rpx 0;
		}
	}

	.tui-auth-login {
		width: 100%;
		display: flex;
		align-items: center;
		justify-content: center;
		padding-bottom: 80rpx;
		padding-top: 20rpx;

		.tui-icon-platform {
			width: 90rpx;
			height: 90rpx;
			display: flex;
			align-items: center;
			justify-content: center;
			position: relative;
			margin-left: 40rpx;

			&::after {
				content: '';
				position: absolute;
				width: 200%;
				height: 200%;
				transform-origin: 0 0;
				transform: scale(0.5, 0.5) translateZ(0);
				box-sizing: border-box;
				left: 0;
				top: 0;
				border-radius: 180rpx;
				border: 1rpx solid $uni-text-color-placeholder;
			}
		}

		.tui-login-logo {
			width: 60rpx;
			height: 60rpx;
		}
	}
}
</style>
